package org.cqu_proj.demo.controller;

import org.cqu_proj.demo.entity.Rating;
import org.cqu_proj.demo.entity.User;
import org.cqu_proj.demo.dto.ResponseResult;
import org.cqu_proj.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private UserService userService;
    // <editor-fold desc="用户账号管理">
    // 用户注册
    @PostMapping("/register")
    public ResponseResult<User> register(@RequestBody User user) {
        System.out.println("进入注册");
        return userService.registerUser(user);
    }

    // 用户登录接口
    @PostMapping("/login")
    public ResponseResult<User> loginUser(@RequestBody User user) {

        // 调用service层的loginUser方法进行登录操作
        return userService.loginUser(user);
    }

    // 修改用户信息
    @PostMapping("/update")
    public ResponseResult<User> updateUser(@RequestBody User user) {
        return userService.updateUserInfo(user);
    }

    // 注销账户
    @GetMapping("/delete/{userId}")
    public ResponseResult<Void> deleteUser(@PathVariable int userId) {
        return userService.deleteUser(userId);
    }

    // 头像上传接口
    @PostMapping("/uploadProfile/{userId}")
    public ResponseResult<String> uploadProfile(@PathVariable int userId, @RequestParam("file") MultipartFile file) {
        return userService.uploadProfile(userId, file);
    }

    //修改密码接口
    @PostMapping("/editPassword")
    public ResponseResult<Void> editPassword(@RequestBody User user) {
        return userService.updatePassword(user);
    }

    // </editor-fold>
    // <editor-fold desc="电影功能r">
    //1.查询用户所有评分数据
    @GetMapping("/getAllRatings")
    public ResponseResult<List<Rating>> findAllRatingByUserId(@RequestParam("newId") int userId){

        return  userService.findAllRatingByUserId(userId);
    }
    //选择个人偏好
    @GetMapping("/choosePrefer")
    public  ResponseResult<String> choosePrefer(String genres ,int userId){
           System.out.println("这是用户第一次选择偏好输入的genres:"+genres);
           this.userService.choosePrefer(userId,genres);
           return  ResponseResult.success("用户选择偏好成功");
    }

    // </editor-fold>
}
